> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/mlfoundations/open_clip/llms.txt
> Use this file to discover all available pages before exploring further.

# Training Configuration

> Complete reference for all OpenCLIP training parameters and hyperparameters

## Overview

OpenCLIP provides extensive configuration options for training CLIP models. This page documents all important training flags and hyperparameters from `params.py`.

To see all available options:

```bash theme={null}
python -m open_clip_train.main --help
```

## Data Configuration

### Training Data

<ParamField path="--train-data" type="string">
  Path to training data. For WebDataset, use glob patterns like `/data/train-{0000..2175}.tar`. Multiple sources can be combined with `::`.

  ```bash theme={null}
  --train-data "/data/cc12m/train-{0000..2175}.tar"
  --train-data "/data/cc12m/train.tar::/data/laion/train.tar"  # Multiple sources
  ```
</ParamField>

<ParamField path="--val-data" type="string">
  Path to validation data (same format as train-data).

  ```bash theme={null}
  --val-data "/data/val.csv"
  ```
</ParamField>

<ParamField path="--train-num-samples" type="integer">
  Total number of samples in training dataset. Required for WebDataset.

  ```bash theme={null}
  --train-num-samples 10968539  # CC12M
  ```
</ParamField>

<ParamField path="--val-num-samples" type="integer">
  Number of samples in validation dataset.
</ParamField>

<ParamField path="--dataset-type" type="string" default="auto">
  Dataset format: `webdataset`, `csv`, `synthetic`, or `auto` (auto-detect).

  ```bash theme={null}
  --dataset-type webdataset
  ```
</ParamField>

<ParamField path="--dataset-resampled" type="boolean">
  Enable sampling with replacement for webdataset. Recommended for large datasets and multiple data sources.

  ```bash theme={null}
  --dataset-resampled
  ```
</ParamField>

### CSV Data Parameters

<ParamField path="--csv-separator" type="string" default="\t">
  Column separator for CSV files (tab by default).

  ```bash theme={null}
  --csv-separator ","  # Use comma separator
  ```
</ParamField>

<ParamField path="--csv-img-key" type="string" default="filepath">
  Column name for image paths in CSV.

  ```bash theme={null}
  --csv-img-key filepath
  ```
</ParamField>

<ParamField path="--csv-caption-key" type="string" default="title">
  Column name for captions in CSV.

  ```bash theme={null}
  --csv-caption-key title
  ```
</ParamField>

### Data Upsampling

<ParamField path="--train-data-upsampling-factors" type="string">
  Upsampling factors for multiple data sources, separated by `::`. Controls relative sampling probability.

  ```bash theme={null}
  --train-data "/data/cc12m/train.tar::/data/cc3m/train.tar" \
  --train-data-upsampling-factors "1::4"  # Sample CC3M 4x more frequently
  ```
</ParamField>

## Model Configuration

### Model Selection

<ParamField path="--model" type="string" default="RN50">
  Model architecture to train. See [Model Architectures](/usage/loading-models) for all options.

  ```bash theme={null}
  --model ViT-B-32
  --model ViT-L-14
  --model RN50
  --model coca_ViT-L-14  # CoCa model
  ```
</ParamField>

<ParamField path="--pretrained" type="string">
  Load pretrained weights. Can be a tag (e.g., `laion2b_s34b_b79k`) or a local path.

  ```bash theme={null}
  --pretrained laion2b_s34b_b79k
  --pretrained /path/to/checkpoint.pt
  ```
</ParamField>

<ParamField path="--pretrained-image" type="boolean">
  Load ImageNet pretrained weights for the image encoder (if available).

  ```bash theme={null}
  --pretrained-image
  ```
</ParamField>

### Model Modifications

<ParamField path="--force-image-size" type="integer">
  Override default image input size.

  ```bash theme={null}
  --force-image-size 224
  --force-image-size 336 336  # Different height/width
  ```
</ParamField>

<ParamField path="--force-context-length" type="integer">
  Override default text context length.

  ```bash theme={null}
  --force-context-length 77
  ```
</ParamField>

<ParamField path="--force-patch-dropout" type="float">
  Override patch dropout probability for ViT models. Use 0.5-0.75 for 2-3x speedup.

  ```bash theme={null}
  --force-patch-dropout 0.5  # 50% patch dropout
  --force-patch-dropout 0.0  # Disable patch dropout (fine-tuning)
  ```
</ParamField>

<ParamField path="--force-quick-gelu" type="boolean">
  Force QuickGELU activation (for compatibility with older checkpoints).
</ParamField>

<ParamField path="--force-custom-text" type="boolean">
  Force separate text tower (CustomTextCLIP architecture).
</ParamField>

## Training Hyperparameters

### Batch Size and Epochs

<ParamField path="--batch-size" type="integer" default="64">
  Batch size per GPU. Total batch size = batch\_size × num\_gpus × accum\_freq.

  ```bash theme={null}
  --batch-size 256
  ```
</ParamField>

<ParamField path="--epochs" type="integer" default="32">
  Number of training epochs.

  ```bash theme={null}
  --epochs 32
  ```
</ParamField>

<ParamField path="--accum-freq" type="integer" default="1">
  Gradient accumulation frequency. Simulates larger batch sizes.

  ```bash theme={null}
  --accum-freq 4  # Effective batch = batch_size × 4
  ```
</ParamField>

### Learning Rate

<ParamField path="--lr" type="float">
  Learning rate. Default depends on model:

  * ViT models: 5e-4
  * ResNet models: 5e-4

  ```bash theme={null}
  --lr 1e-3
  --lr 5e-4
  ```
</ParamField>

<ParamField path="--warmup" type="integer" default="10000">
  Number of warmup steps (linear warmup from 0 to lr).

  ```bash theme={null}
  --warmup 10000
  ```
</ParamField>

<ParamField path="--lr-scheduler" type="string" default="cosine">
  Learning rate schedule: `cosine`, `const`, or `const-cooldown`.

  ```bash theme={null}
  --lr-scheduler cosine
  --lr-scheduler const  # Constant LR after warmup
  --lr-scheduler const-cooldown  # Constant with cooldown
  ```
</ParamField>

<ParamField path="--epochs-cooldown" type="integer">
  Number of cooldown epochs for `const-cooldown` scheduler.

  ```bash theme={null}
  --lr-scheduler const-cooldown \
  --epochs-cooldown 5
  ```
</ParamField>

<ParamField path="--lr-cooldown-end" type="float" default="0.0">
  End learning rate for cooldown.

  ```bash theme={null}
  --lr-cooldown-end 1e-6
  ```
</ParamField>

<ParamField path="--lr-cooldown-power" type="float" default="1.0">
  Power for polynomial cooldown (1.0 = linear).

  ```bash theme={null}
  --lr-cooldown-power 1.0
  ```
</ParamField>

### Optimizer

<ParamField path="--opt" type="string" default="adamw">
  Optimizer choice. Use `adamw` or `timm/{optimizer}` for timm optimizers.

  ```bash theme={null}
  --opt adamw
  --opt timm/sgd
  ```
</ParamField>

<ParamField path="--beta1" type="float">
  Adam beta1 parameter. Default:

  * ViT: 0.9
  * ResNet: 0.9

  ```bash theme={null}
  --beta1 0.9
  ```
</ParamField>

<ParamField path="--beta2" type="float">
  Adam beta2 parameter. Default:

  * ViT: 0.98
  * ResNet: 0.999

  ```bash theme={null}
  --beta2 0.98
  ```
</ParamField>

<ParamField path="--eps" type="float">
  Adam epsilon parameter. Default:

  * ViT: 1e-6
  * ResNet: 1e-8

  ```bash theme={null}
  --eps 1e-6
  ```
</ParamField>

<ParamField path="--wd" type="float" default="0.2">
  Weight decay (L2 regularization).

  ```bash theme={null}
  --wd 0.2
  --wd 0.1
  ```
</ParamField>

<ParamField path="--momentum" type="float">
  Momentum for timm optimizers (SGD, etc.).

  ```bash theme={null}
  --momentum 0.9
  ```
</ParamField>

### Gradient Clipping

<ParamField path="--grad-clip-norm" type="float">
  Gradient clipping norm. Prevents gradient explosion.

  ```bash theme={null}
  --grad-clip-norm 1.0
  ```
</ParamField>

## Precision and Memory

### Precision

<ParamField path="--precision" type="string" default="amp">
  Training precision: `amp`, `amp_bf16`, `bf16`, `fp16`, `fp32`.

  ```bash theme={null}
  --precision amp        # Automatic Mixed Precision (FP16) - Recommended
  --precision amp_bf16   # AMP with BFloat16 (A100/H100)
  --precision fp32       # Full precision (slow, baseline)
  ```
</ParamField>

### Memory Optimization

<ParamField path="--grad-checkpointing" type="boolean">
  Enable gradient checkpointing to reduce memory usage (slower training).

  ```bash theme={null}
  --grad-checkpointing
  ```
</ParamField>

<ParamField path="--local-loss" type="boolean">
  Calculate loss with local features @ global (reduces memory from O(n²) to O(n)).

  ```bash theme={null}
  --local-loss
  ```
</ParamField>

<ParamField path="--gather-with-grad" type="boolean">
  Enable gradient flow through feature gathering (use with --local-loss).

  ```bash theme={null}
  --gather-with-grad
  ```
</ParamField>

<Tip>
  Always use `--local-loss` and `--gather-with-grad` together for multi-GPU training (8+ GPUs). See [Distributed Training](/training/distributed-training).
</Tip>

## Data Loading

<ParamField path="--workers" type="integer" default="4">
  Number of data loading workers per GPU.

  ```bash theme={null}
  --workers 8  # 8 workers per GPU
  ```
</ParamField>

<Tip>
  Recommended: 4-8 workers per GPU for optimal performance.
</Tip>

## Image Preprocessing

<ParamField path="--image-mean" type="float[]">
  Override image normalization mean (RGB).

  ```bash theme={null}
  --image-mean 0.485 0.456 0.406  # ImageNet statistics
  ```
</ParamField>

<ParamField path="--image-std" type="float[]">
  Override image normalization std (RGB).

  ```bash theme={null}
  --image-std 0.229 0.224 0.225  # ImageNet statistics
  ```
</ParamField>

<ParamField path="--image-interpolation" type="string">
  Image resize interpolation: `bicubic`, `bilinear`, or `random`.

  ```bash theme={null}
  --image-interpolation bicubic
  ```
</ParamField>

<ParamField path="--image-resize-mode" type="string">
  Image resize mode: `shortest`, `longest`, or `squash` (inference only).

  ```bash theme={null}
  --image-resize-mode shortest
  ```
</ParamField>

<ParamField path="--aug-cfg" type="key=value">
  Data augmentation configuration (key-value pairs).

  ```bash theme={null}
  --aug-cfg scale_range=0.08::1.0 ratio_range=0.75::1.33
  ```
</ParamField>

## Model Locking (Transfer Learning)

### Image Tower

<ParamField path="--lock-image" type="boolean">
  Lock (freeze) entire image encoder.

  ```bash theme={null}
  --lock-image
  ```
</ParamField>

<ParamField path="--lock-image-unlocked-groups" type="integer" default="0">
  Leave last N image tower layer groups unlocked.

  ```bash theme={null}
  --lock-image --lock-image-unlocked-groups 2  # Freeze all but last 2 groups
  ```
</ParamField>

<ParamField path="--lock-image-freeze-bn-stats" type="boolean">
  Freeze BatchNorm running statistics in locked layers.

  ```bash theme={null}
  --lock-image-freeze-bn-stats
  ```
</ParamField>

### Text Tower

<ParamField path="--lock-text" type="boolean">
  Lock (freeze) entire text encoder.

  ```bash theme={null}
  --lock-text
  ```
</ParamField>

<ParamField path="--lock-text-unlocked-layers" type="integer" default="0">
  Leave last N text tower layers unlocked.

  ```bash theme={null}
  --lock-text --lock-text-unlocked-layers 10  # Train last 10 layers
  ```
</ParamField>

<ParamField path="--lock-text-freeze-layer-norm" type="boolean">
  Freeze LayerNorm in locked text layers.

  ```bash theme={null}
  --lock-text-freeze-layer-norm
  ```
</ParamField>

## Checkpointing and Logging

### Checkpoints

<ParamField path="--save-frequency" type="integer" default="1">
  Save checkpoint every N epochs.

  ```bash theme={null}
  --save-frequency 1  # Save every epoch
  --save-frequency 5  # Save every 5 epochs
  ```
</ParamField>

<ParamField path="--save-most-recent" type="boolean">
  Save most recent checkpoint as `epoch_latest.pt`.

  ```bash theme={null}
  --save-most-recent
  ```
</ParamField>

<ParamField path="--delete-previous-checkpoint" type="boolean">
  Delete previous checkpoint after saving new one (saves disk space).

  ```bash theme={null}
  --delete-previous-checkpoint
  ```
</ParamField>

<ParamField path="--resume" type="string">
  Resume training from checkpoint path or "latest".

  ```bash theme={null}
  --resume /path/to/checkpoint.pt
  --resume latest  # Resume from latest checkpoint
  ```
</ParamField>

### Logging

<ParamField path="--logs" type="string" default="./logs/">
  Directory for logs and checkpoints.

  ```bash theme={null}
  --logs ./logs/
  ```
</ParamField>

<ParamField path="--name" type="string">
  Experiment name (defaults to auto-generated based on timestamp and config).

  ```bash theme={null}
  --name "vit-b32-cc12m-experiment"
  ```
</ParamField>

<ParamField path="--report-to" type="string">
  Logging backends: `tensorboard`, `wandb`, or `tensorboard,wandb`.

  ```bash theme={null}
  --report-to tensorboard
  --report-to wandb
  --report-to tensorboard,wandb  # Both
  ```
</ParamField>

<ParamField path="--log-every-n-steps" type="integer" default="100">
  Log training metrics every N steps.

  ```bash theme={null}
  --log-every-n-steps 100
  ```
</ParamField>

### Weights & Biases

<ParamField path="--wandb-project-name" type="string" default="open-clip">
  W\&B project name.

  ```bash theme={null}
  --wandb-project-name "my-clip-experiments"
  ```
</ParamField>

<ParamField path="--wandb-notes" type="string">
  Notes for W\&B run.

  ```bash theme={null}
  --wandb-notes "Testing new learning rate schedule"
  ```
</ParamField>

## Evaluation

<ParamField path="--imagenet-val" type="string">
  Path to ImageNet validation set for zero-shot evaluation during training.

  ```bash theme={null}
  --imagenet-val /data/imagenet/validation/
  ```
</ParamField>

<ParamField path="--imagenet-v2" type="string">
  Path to ImageNet-v2 for additional zero-shot evaluation.

  ```bash theme={null}
  --imagenet-v2 /data/imagenet-v2/
  ```
</ParamField>

<ParamField path="--zeroshot-frequency" type="integer" default="2">
  Run zero-shot evaluation every N epochs.

  ```bash theme={null}
  --zeroshot-frequency 1  # Every epoch
  ```
</ParamField>

<ParamField path="--val-frequency" type="integer" default="1">
  Run validation every N epochs.

  ```bash theme={null}
  --val-frequency 1
  ```
</ParamField>

## CoCa-Specific Parameters

<ParamField path="--coca-contrastive-loss-weight" type="float" default="1.0">
  Weight for CoCa contrastive loss.

  ```bash theme={null}
  --coca-contrastive-loss-weight 1.0
  ```
</ParamField>

<ParamField path="--coca-caption-loss-weight" type="float" default="2.0">
  Weight for CoCa caption generation loss.

  ```bash theme={null}
  --coca-caption-loss-weight 2.0
  ```
</ParamField>

<Tip>
  For CoCa fine-tuning on captioning only:

  ```bash theme={null}
  --coca-contrastive-loss-weight 0 \
  --coca-caption-loss-weight 1
  ```
</Tip>

## Distributed Training

<ParamField path="--dist-url" type="string">
  URL for distributed training initialization.

  ```bash theme={null}
  --dist-url tcp://localhost:12345
  ```
</ParamField>

<ParamField path="--dist-backend" type="string">
  Distributed backend: `nccl` (NVIDIA GPU), `hccl` (Ascend NPU), or `gloo` (CPU).

  ```bash theme={null}
  --dist-backend nccl  # Default for GPU
  ```
</ParamField>

<ParamField path="--horovod" type="boolean">
  Use Horovod for distributed training.

  ```bash theme={null}
  --horovod
  ```
</ParamField>

<ParamField path="--ddp-static-graph" type="boolean">
  Enable static graph optimization for DDP (PyTorch >= 1.11).

  ```bash theme={null}
  --ddp-static-graph
  ```
</ParamField>

<ParamField path="--use-bn-sync" type="boolean">
  Use synchronized batch normalization across GPUs.

  ```bash theme={null}
  --use-bn-sync
  ```
</ParamField>

## Advanced Options

### Compilation

<ParamField path="--torchcompile" type="boolean">
  Compile model with torch.compile() (PyTorch >= 2.0).

  ```bash theme={null}
  --torchcompile
  ```
</ParamField>

<ParamField path="--torchscript" type="boolean">
  TorchScript the model.

  ```bash theme={null}
  --torchscript
  ```
</ParamField>

<ParamField path="--trace" type="boolean">
  Trace model with torch.jit.trace (inference only).

  ```bash theme={null}
  --trace
  ```
</ParamField>

### Model Distillation

<ParamField path="--distill-model" type="string">
  Teacher model architecture for distillation.

  ```bash theme={null}
  --distill-model ViT-L-14
  ```
</ParamField>

<ParamField path="--distill-pretrained" type="string">
  Teacher model pretrained weights.

  ```bash theme={null}
  --distill-pretrained openai
  ```
</ParamField>

### Loss Configuration

<ParamField path="--siglip" type="boolean">
  Use SigLip (sigmoid) loss instead of standard CLIP loss.

  ```bash theme={null}
  --siglip
  ```
</ParamField>

<ParamField path="--loss-dist-impl" type="string">
  Distributed loss implementation override.

  ```bash theme={null}
  --loss-dist-impl custom
  ```
</ParamField>

### Remote Syncing

<ParamField path="--remote-sync" type="string">
  Remote path to sync checkpoints (S3 bucket or filesystem).

  ```bash theme={null}
  --remote-sync s3://my-bucket/checkpoints
  ```
</ParamField>

<ParamField path="--remote-sync-frequency" type="integer" default="300">
  Sync to remote every N seconds.

  ```bash theme={null}
  --remote-sync-frequency 600  # Sync every 10 minutes
  ```
</ParamField>

<ParamField path="--remote-sync-protocol" type="string" default="s3">
  Protocol for remote sync: `s3` or `fsspec`.

  ```bash theme={null}
  --remote-sync-protocol s3
  ```
</ParamField>

### Experimental

<ParamField path="--use-bnb-linear" type="string">
  Use bitsandbytes linear layers for int8 training (experimental).

  ```bash theme={null}
  --use-bnb-linear SwitchBackLinearGlobal
  ```
</ParamField>

### Other

<ParamField path="--seed" type="integer" default="0">
  Random seed for reproducibility.

  ```bash theme={null}
  --seed 42
  ```
</ParamField>

<ParamField path="--device" type="string" default="cuda">
  Device for training: `cuda` or `cpu`.

  ```bash theme={null}
  --device cuda
  ```
</ParamField>

<ParamField path="--cache-dir" type="string">
  Override default cache directory for model/tokenizer downloads.

  ```bash theme={null}
  --cache-dir /path/to/cache
  ```
</ParamField>

<ParamField path="--debug" type="boolean">
  Enable debug logging.

  ```bash theme={null}
  --debug
  ```
</ParamField>

<ParamField path="--log-local" type="boolean">
  Log on local master (each node) instead of global master only.

  ```bash theme={null}
  --log-local
  ```
</ParamField>

<ParamField path="--copy-codebase" type="boolean">
  Copy entire codebase to log directory.

  ```bash theme={null}
  --copy-codebase
  ```
</ParamField>

## Example Configurations

### Small-Scale Training (RN50 on CC3M)

```bash theme={null}
python -m open_clip_train.main \
    --train-data "/data/cc3m/train.csv" \
    --dataset-type csv \
    --csv-img-key filepath \
    --csv-caption-key title \
    --batch-size 256 \
    --precision amp \
    --workers 4 \
    --warmup 2000 \
    --lr 1e-3 \
    --wd 0.1 \
    --epochs 30 \
    --model RN50 \
    --save-frequency 5 \
    --report-to tensorboard
```

### Medium-Scale Training (ViT-B/32 on CC12M)

```bash theme={null}
torchrun --nproc_per_node 4 -m open_clip_train.main \
    --train-data "/data/cc12m/cc12m-{0000..2175}.tar" \
    --train-num-samples 10968539 \
    --dataset-type webdataset \
    --dataset-resampled \
    --batch-size 320 \
    --precision amp \
    --workers 6 \
    --imagenet-val /data/imagenet/validation/ \
    --warmup 10000 \
    --lr 1e-3 \
    --wd 0.1 \
    --epochs 32 \
    --model ViT-B-32 \
    --save-frequency 1 \
    --zeroshot-frequency 1 \
    --local-loss \
    --gather-with-grad \
    --report-to wandb
```

### Large-Scale Training (ViT-L/14 on LAION-400M)

```bash theme={null}
srun python -u src/open_clip_train/main.py \
    --train-data "/data/laion400m/{00000..41455}.tar" \
    --train-num-samples 400000000 \
    --dataset-type webdataset \
    --dataset-resampled \
    --batch-size 128 \
    --precision amp \
    --grad-checkpointing \
    --workers 8 \
    --warmup 10000 \
    --lr 5e-4 \
    --wd 0.2 \
    --epochs 32 \
    --model ViT-L-14 \
    --save-frequency 1 \
    --zeroshot-frequency 2 \
    --local-loss \
    --gather-with-grad \
    --force-patch-dropout 0.5 \
    --report-to wandb \
    --remote-sync s3://bucket/checkpoints \
    --delete-previous-checkpoint
```

## Recommended Settings by Model

### ViT-B/32

```bash theme={null}
--model ViT-B-32 \
--lr 5e-4 \
--beta1 0.9 \
--beta2 0.98 \
--eps 1e-6 \
--batch-size 256-512 \
--precision amp
```

### ViT-L/14

```bash theme={null}
--model ViT-L-14 \
--lr 5e-4 \
--beta1 0.9 \
--beta2 0.98 \
--eps 1e-6 \
--batch-size 128-256 \
--precision amp \
--grad-checkpointing \
--force-patch-dropout 0.5
```

### RN50

```bash theme={null}
--model RN50 \
--lr 5e-4 \
--beta1 0.9 \
--beta2 0.999 \
--eps 1e-8 \
--batch-size 256-512 \
--precision amp
```

## Next Steps

<CardGroup cols={2}>
  <Card title="Single-Node Training" icon="server" href="/training/single-node">
    Apply these configurations to single-node training
  </Card>

  <Card title="Distributed Training" icon="rocket" href="/training/distributed-training">
    Configure distributed training optimizations
  </Card>

  <Card title="Data Preparation" icon="database" href="/training/data-preparation">
    Configure data loading and preprocessing
  </Card>

  <Card title="Fine-tuning" icon="arrows-rotate" href="/training/fine-tuning">
    Configure fine-tuning from pretrained models
  </Card>
</CardGroup>
